function [ zombie ] = necromancy( skeleton, distances )
% Reconstruct an image from a skeleton and the distance transform

[M, N] = size(skeleton);
zombie = zeros(M,N);
for i = 1:1:M
    for j = 1:1:N
        radius = floor(distances(i,j));
        if skeleton(i,j) == 1 && radius > 0
            disk = ceil(fspecial('disk',radius));
            xmin = max(0, i-radius);
            xmax = min(M, i+radius);
            ymin = max(0, j-radius);
            ymax = min(N, j+radius);
            for x = xmin:1:xmax
               for y = ymin:1:ymax
                  zombie(x,y) = zombie(x,y) | disk(x-xmin+1,y-ymin+1);
                  %for an acumulative (and cooler) version
                  %zombie(x,y) = zombie(x,y) + disk(x-xmin+1,y-ymin+1);
                  
               end
            end
        end    
    end
end

end

